package com.swxy.club.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import com.swxy.club.enums.CommonEnum;


/**
 * @author 易
 */
public class EnumFlatSerializer extends JsonSerializer<CommonEnum> {
    @Override
    public void serialize(
            CommonEnum enumObj,
            JsonGenerator gen,
            SerializerProvider provider
    ) throws IOException {
        // 写入主字段（如 "status": "normal"）
        gen.writeString(enumObj.getValue());

        // 动态生成 Zs 后缀字段（如 "statusZs": "正常"）
        String fieldName = gen.getOutputContext().getCurrentName() + "Zs";
        gen.writeFieldName(fieldName);
        gen.writeString(enumObj.getDescription());
    }
}